define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {

    var Controller = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'phone/index' + location.search,
                    add_url: 'phone/add',
                    edit_url: 'phone/edit',
                    del_url: 'phone/del',
                    multi_url: 'phone/multi',
                    import_url: 'phone/import',
                    table: 'phone',
                }
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'id',
                fixedColumns: true,
                fixedRightNumber: 1,
                columns: [
                    [
                        {checkbox: true},
                        // {field: 'id', title: __('Id')},
                        {field: 'store.name', title: __('S_id'), operate: 'LIKE', table: table, class: 'autocontent', formatter: Table.api.formatter.content},
                        {field: 'admin.nickname', title: __('A_id'), operate: 'LIKE'},
                        {field: 'admin.mobile', title: __('Admin.mobile'), operate: 'LIKE'},
                        {field: 'admin.jnum', title: __('Admin.jnum'), operate: 'LIKE'},
                        {field: 'reg_datetime', title: __('Reg_datetime'), operate:'RANGE', addclass:'datetimerange', autocomplete:false},
                        {field: 'outbound_enum', title: __('Outbound_enum'), searchList: {"0":__('Outbound_enum 0'),"1":__('Outbound_enum 1'),"2":__('Outbound_enum 2')}, formatter: Table.api.formatter.normal},
                        {field: 'sales_enum', title: __('Sales_enum'), searchList: {"0":__('Sales_enum 0'),"1":__('Sales_enum 1'),"2":__('Sales_enum 2')}, formatter: Table.api.formatter.normal},
                        {field: 'deposit', title: __('Deposit'), operate:'BETWEEN'},
                        {field: 'sales_offer_price', title: __('Sales_offer_price'), operate:'BETWEEN'},
                        {field: 'sales_price', title: __('Sales_price'), operate:'BETWEEN'},
                        {field: 'displace_enum', title: __('Displace_enum'), searchList: {"0":__('Displace_enum 0'),"1":__('Displace_enum 1')}, formatter: Table.api.formatter.normal},
                        {field: 'displace_price', title: __('Displace_price'), operate:'BETWEEN'},
                        {field: 'accessory_set', title: __('Accessory_set'), searchList: {"0":__('Accessory_set 0'),"1":__('Accessory_set 1'),"2":__('Accessory_set 2')}, operate:'FIND_IN_SET', formatter: Table.api.formatter.label},
                        {field: 'accessory_profit', title: __('Accessory_profit'), operate:'BETWEEN'},
                        {field: 'pay_enum', title: __('Pay_enum'), searchList: {"0":__('Pay_enum 0'),"1":__('Pay_enum 1'),"2":__('Pay_enum 2'),"3":__('Pay_enum 3')}, formatter: Table.api.formatter.normal},
                        {field: 'all_profit', title: __('All_profit'), operate:'BETWEEN'},
                        {field: 'c_name', title: __('C_name'), operate: 'LIKE', table: table, class: 'autocontent', formatter: Table.api.formatter.content},
                        {field: 'c_sex', title: __('C_sex'), searchList: {"1":__('C_sex 1'),"0":__('C_sex 0')}, formatter: Table.api.formatter.normal},
                        {field: 'c_birthday_datetime', title: __('C_birthday_datetime'), operate:'RANGE', addclass:'datetimerange', autocomplete:false},
                        {field: 'c_phone', title: __('C_phone'), operate: 'LIKE', table: table, class: 'autocontent', formatter: Table.api.formatter.content},
                        {field: 'follow_enum', title: __('Follow_enum'), searchList: {"0":__('Follow_enum 0'),"1":__('Follow_enum 1')}, formatter: Table.api.formatter.normal},
                        {field: 'gift_enum', title: __('Gift_enum'), searchList: {"0":__('Gift_enum 0'),"1":__('Gift_enum 1')}, formatter: Table.api.formatter.normal},
                        {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate}
                    ]
                ]
            });

            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        add: function () {
            $("#c-s_id").change(function () {
                $("#c-a_id_text").val('');
                $("#c-a_id").val('');
            })
            $("#c-a_id").data("params", function (obj) {
                //obj为SelectPage对象
                return {custom: {sid: $("#c-s_id").val()}};
            });
            Controller.api.bindevent();
        },
        edit: function () {
            $("#c-s_id").change(function () {
                $("#c-a_id_text").val('');
                $("#c-a_id").val('');
            })
            $("#c-a_id").data("params", function (obj) {
                //obj为SelectPage对象
                return {custom: {sid: $("#c-s_id").val()}};
            });
            Controller.api.bindevent();
        },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            }
        }
    };
    return Controller;
});
